<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="lib/vue.js"></script>
</head>
<body>
<div id="root">
    <button @click="num++">{{num}}</button>
    <button @click="obj.age++">obj->age:{{obj.age}}</button>
    <button @click="obj.username+='!'">obj->username:{{obj.username}}</button>
</div>
</body>
<script>
    // $watch是Vue.prototype中的一个函数
	const vm = new Vue({
		el: "#root",
        data:{
			num:10,
            obj:{
				age:100,
                username:"lisi"
            }
        },

        mounted(){
			this.$watch("num",function(newValue,oldValue){
				console.log(newValue,oldValue)
			})
            // this.$watch("obj.age",function(newValue,oldValue){
			// 	console.log("obj.age",newValue,oldValue)
            // })

            // this.$watch("obj",function(newValue,oldValue){
			// 	console.log("obj",newValue,oldValue)
            // },{
			// 	deep:true
            // })

            this.$watch("obj",{
				handler(newValue,oldValue){
					console.log("obj",newValue,oldValue)
                },
                deep:true
            })
        }
	});
	// vm.$watch("num",function(newValue,oldValue){
	// 	console.log(newValue,oldValue)
    // })
</script>
</html>